<template>
  <div>
    退单详情
    <div>
      退单状态:{{ info.status | codeToText }}
    </div>
    <div v-if="info.status == 0 ">
      <el-form ref="form" :model="form" label-width="80px" :inline="false" size="normal">
        <el-form-item label="退款金额">
          <el-input v-model="form.returnAmount" />
        </el-form-item>
        <el-form-item label="处理人">
          <el-input v-model="form.handleMan" />
        </el-form-item>
        <el-form-item label="处理备注">
          <el-input v-model="form.handleNote" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">同意退款</el-button>
          <el-button @click="reject">拒绝退款</el-button>
        </el-form-item>
      </el-form>

    </div>
    <div v-if="info.status == 1 ">
      <el-form ref="form" :model="formData" label-width="80px" :inline="false" size="normal">

        <el-form-item label="收货人">
          <el-input v-model="formData.receiveMan" />
        </el-form-item>
        <el-form-item label="收货备注">
          <el-input v-model="formData.receiveNote" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="receive">确认收货</el-button>
        </el-form-item>
      </el-form>

    </div>
  </div>
</template>

<script>
import {
  orderReturn,
  agreeApply,
  rejectApply,
  receiveProduct
} from '@/api/orderManage/returnOrder/returnOrderInfo/index.js'
export default {
  filters: {
    codeToText(val) {
      var arr = ['待处理', '退货中', '已完成', '已拒绝']
      return arr[val]
    }
  },
  data() {
    return {
      info: {},
      form: {
        id: this.$route.params.id,
        handleMan: '',
        handleNote: '',
        returnAmount: ''
      },
      formData: {
        id: this.$route.params.id,
        receiveMan: '',
        receiveNote: ''
      }
    }
  },
  computed: {

  },
  created() {
    this.init()
  },
  mounted() {

  },
  methods: {
    receive() {
      receiveProduct(this.formData)
        .then(res => {
          this.init()
        })
    },
    onSubmit() {
      agreeApply(this.form)
        .then(res => {
          this.init()
        })
    },
    reject() {
      rejectApply(this.form)
        .then(res => {
          this.init()
        })
    },
    init() {
      orderReturn(this.$route.params.id)
        .then(res => {
          console.log(res)
          this.info = res.data.orderReturnApply
        })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
